package com.gitee.wsl.ext.list

fun <T: Any> Iterable<T>.separated(block: (T, T) -> T): List<T> {
    val res = mutableListOf<T>()
    var prev: T? = null
    var first = true
    for (cur in this) {
        if (!first && prev != null) {
            val sep = block(prev, cur)
            res.add(sep)
        }
        res.add(cur)
        prev = cur
        first = false
    }
    return res
}